]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
remote-search: apply sort-order from GSettings
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 1 Nov 2012 19:57:18 +0000 (15:57 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 19 Nov 2012 16:45:21 +0000 (11:45 -0500)
Sort providers according to the GSettings state, and make sure to reload
them as soon as the sort order changes.

https://bugzilla.gnome.org/show_bug.cgi?id=687491

js/ui/remoteSearch.js
js/ui/viewSelector.js

index 45fbda50a3163a56d9d1d611bbf8ee43c6d599f1..c9b25c6ac2a1b338ea2f953ac054da99011847b0 100644 (file)
@@ -116,6 +116,46 @@ function remoteProvidersDirLoaded(loadState) {
     if (loadState.numLoading > 0)
         return;
 
+    let searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
+    let sortOrder = searchSettings.get_strv('sort-order');
+    let numSorted = sortOrder.length;
+
+    loadState.loadedProviders.sort(
+        function(providerA, providerB) {
+            let idxA, idxB;
+            let appIdA, appIdB;
+
+            appIdA = providerA.appInfo.get_id();
+            appIdB = providerB.appInfo.get_id();
+
+            idxA = sortOrder.indexOf(appIdA);
+            idxB = sortOrder.indexOf(appIdB);
+
+            // if no provider is found in the order, use alphabetical order
+            if ((idxA == -1) && (idxB == -1))
+                return GLib.utf8_collate(providerA.title, providerB.title);
+
+            if (numSorted > 1) {
+                // if providerA is the last, it goes after everything
+                if ((idxA + 1) == numSorted)
+                    return 1;
+                // if providerB is the last, it goes after everything
+                else if ((idxB + 1) == numSorted)
+                    return -1;
+            }
+
+            // if providerA isn't found, it's sorted after providerB
+            if (idxA == -1)
+                return 1;
+
+            // if providerB isn't found, it's sorted after providerA
+            if (idxB == -1)
+                return -1;
+
+            // finally, if both providers are found, return their order in the list
+            return (idxA - idxB);
+        });
+
     loadState.loadedProviders.forEach(
         function(provider) {
             loadState.addProviderCallback(provider);
index d2edfcbedb978bfe36cfc2aa9badca28bf7b6c54..bee5bd742ed50d2da25a97d73396a4ea26583380 100644 (file)
@@ -96,6 +96,7 @@ const ViewSelector = new Lang.Class({
 
         this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
         this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
+        this._searchSettings.connect('changed::sort-order', Lang.bind(this, this._reloadRemoteProviders));
 
         // Default search providers
         // Wanda comes obviously first